/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author Michael
 */
@Entity
public class Restaurant implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id_restaurant")
    private Long id_restaurant;

    @NotEmpty
    private String nom;
    
    @NotEmpty
    private String adresse;
    
    @NotEmpty
    private String telephone;
    
    @Email
    private String mail;
    
    @OneToMany(mappedBy = "resto")
    private List<Employe> employes;
    
    @ManyToOne
    @JoinColumn(name="platdujour")
    private Menu platDuJour;
    
    @OneToMany(mappedBy = "resto",fetch= FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    private List<TableResto> tables;
    
    @ManyToMany(mappedBy = "dansRestaurants",fetch= FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    private List<Menu> menus;
    
    @ManyToMany(mappedBy = "dansRestaurants",fetch= FetchType.EAGER)
    @Fetch(FetchMode.SUBSELECT)
    private List<Produit> produits;

    public Restaurant() {
    }

    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public List<Employe> getEmployes() {
        return employes;
    }

    public void setEmployes(List<Employe> employes) {
        this.employes = employes;
    }

    public Long getId_restaurant() {
        return id_restaurant;
    }

    public void setId_restaurant(Long id_restaurant) {
        this.id_restaurant = id_restaurant;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public Menu getPlatDuJour() {
        return platDuJour;
    }

    public void setPlatDuJour(Menu platDuJour) {
        this.platDuJour = platDuJour;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    
    public void addEmploye(Employe e)
    {
        if(employes == null)
        {
            employes = new ArrayList();
        }
        if(!employes.contains(e))
        {
            this.employes.add(e);
        }
    }

    public List<TableResto> getTables() {
        return tables;
    }

    public void setTables(List<TableResto> tables) {
        this.tables = tables;
    }

    public List<Menu> getMenus() {
        return menus;
    }

    public void setMenus(List<Menu> menus) {
        this.menus = menus;
    }
    
    public void addMenu(Menu menu)
    {
        if(menus == null)
        {
            menus = new ArrayList();
        }
        if(!menus.contains(menu))
        {
            this.menus.add(menu);
        }
    }
    
    public void removeMenu(Menu menu)
    {
        if(menus.contains(menu))
        {
            this.menus.remove(menu);
        }
    }

    public List<Produit> getProduits() {
        return produits;
    }

    public void setProduits(List<Produit> produits) {
        this.produits = produits;
    }
    
    public void addProduit(Produit produit)
    {
        if(produits == null)
        {
            produits = new ArrayList();
        }
        if(!produits.contains(produit))
        {
            this.produits.add(produit);
        }
    }
    
    public void removeProduit(Produit produit)
    {
        if(produits.contains(produit))
        {
            this.produits.remove(produit);
        }
    }
    
    public void addTable(TableResto table)
    {
        if(tables == null)
        {
            tables = new ArrayList();
        }
        if(!tables.contains(table))
        {
            this.tables.add(table);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Restaurant other = (Restaurant) obj;
        if (this.id_restaurant != other.id_restaurant && (this.id_restaurant == null || !this.id_restaurant.equals(other.id_restaurant))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + (this.id_restaurant != null ? this.id_restaurant.hashCode() : 0);
        return hash;
    }
    
}
